import { createSlice, PayloadAction } from '@reduxjs/toolkit'
export interface loginType {
  menuList: IRoutesType[] //菜单
  routeList: IRoutesType[] //所有routes
  userRouteList: IRoutesType[] //用户所拥有的routes
  buttonCodeList: string[] //用户所拥有的buttonCode
  DICTDATA: Record<string, IOptionItem[]>
}

const initialState: loginType = {
  menuList: [],
  routeList: [],
  userRouteList: [],
  buttonCodeList: [],
  DICTDATA: {},
}
export const loginSlice = createSlice({
  name: 'login',
  initialState,
  reducers: {
    changeMenuList(state, action: PayloadAction<IRoutesType[]>) {
      state.menuList = action.payload
    },
    changeRouteList(state, action: PayloadAction<IRoutesType[]>) {
      state.routeList = action.payload
    },
    changeUserRouteList(state, action: PayloadAction<IRoutesType[]>) {
      state.userRouteList = action.payload
    },
    changeButtonCodeList(state, action: PayloadAction<string[]>) {
      state.buttonCodeList = action.payload
    },
    changeDictData(state, action: PayloadAction<Record<string, IOptionItem[]>>) {
      state.DICTDATA = action.payload
    },
  },
})
export const { changeMenuList, changeUserRouteList, changeRouteList, changeDictData, changeButtonCodeList } =
  loginSlice.actions
export default loginSlice.reducer
